//
//  main.swift
//  15.结构体和类
//
//  Created by 左忠飞 on 2021/8/4.
//

//import Foundation


var myTown = Town()
myTown.population = 1000
myTown.printDescription()

myTown.changePopulation(by: 500)
//myTown.printDescription()
//
//let genericMonster = Monster()
//genericMonster.town = myTown
//genericMonster.terrorizeTown()


let fredTheZombie = Zombie()
fredTheZombie.town = myTown
fredTheZombie.terrorizeTown()
fredTheZombie.town?.printDescription()


print(Zombie.makeSpookNoise())


let myTownSize = myTown.townSize
print(myTownSize)

//懒加载属性只在第一次使用的时候初始化,后边在调用不会再次走初始化函数
//所以这里改变了镇子的人数,但是镇子的zize属性值没有发生变化
myTown.changePopulation(by: 1000_000)
print(myTown.townSize)

print("镇子规模计算属性:\(myTown.townSize2)")
myTown.changePopulation(by: -1000_000)
print("镇子规模计算属性:\(myTown.townSize2)")


//读写属性
print("Victim pool: \(fredTheZombie.victimPool)")


//读取只读的类型属性
print(Zombie.spookyNoise)

print("Monster isTerrifying:\(Monster.isTerrifying)")
print("Zombie isTerrifying:\(Zombie.isTerrifying)")

